package com.infore.remoteControl.controller;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.infore.remoteControl.constant.Constants;
import com.infore.remoteControl.dto.InstructionsDto;
import com.infore.remoteControl.entity.instructionsEntity.Instructions;
import com.infore.remoteControl.enums.ResultStatus;
import com.infore.remoteControl.select.dto.QueryParamDto;
import com.infore.remoteControl.service.InstructionsService;
import com.infore.remoteControl.util.ResultEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 指令控制器
 * 
 * @author Cold
 *
 */
@Api(value = "指令管理接口", tags = { "指令管理接口" })
@RestController
@RequestMapping("/instructions")
public class InstructionsController {

	@Autowired
	private InstructionsService instructionsService;

	@ApiOperation(value = "查询指令通用接口")
	@ResponseBody
	@RequestMapping(value = "/query", method = RequestMethod.POST)
	public ResultEntity query(@RequestBody(required = false) QueryParamDto queryParamDto) {
		return instructionsService.query(queryParamDto);
	}

	@ApiOperation(value = "编辑指令通用接口")
	@ResponseBody
	@RequestMapping(value = "/edit", method = RequestMethod.POST)
	public ResultEntity editInstructions(@RequestBody Instructions instruction) {
		return instructionsService.edit(instruction);
	}

	@ApiOperation(value = "删除指令通用接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "ids", value = "指令ID", paramType = "query", required = true, dataType = "String") })
	@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
	public ResultEntity deleteInstructions(String ids) {
		if (StringUtils.isBlank(ids)) {
			return new ResultEntity(ResultStatus.ERROR, Constants.DELETE_FAILUE);
		}
		return instructionsService.delete(ids);
	}

	@ApiOperation(value = "验证指令通用接口")
	@ResponseBody
	@RequestMapping(value = "/validate", method = RequestMethod.POST)
	public ResultEntity validate(@RequestBody Instructions instructions) {
		return instructionsService.validate(instructions);
	}

	@ApiOperation(value = "生成指令数据")
	@ResponseBody
	@RequestMapping(value = "/datas", method = RequestMethod.POST)
	public ResultEntity createInstructionsDatas(@RequestBody List<InstructionsDto> instructionsDtoList) {
		return instructionsService.createInstructionsDatas(instructionsDtoList);
	}
}
